﻿<!-- #include file="../ding.asp" -->
<!-- #include file="../mymin.asp" -->
<!--#include file="upload.inc"-->
<!--#include file="upload_5xsoft.inc"-->
<%Call head2%>
<title>WAP2.0文件上传</title>
</head>
<body>
<%

Server.ScriptTimeOut=999999

dim upload,file,formName,formPath,filename,fileExt,filesize
dim ranNum,allowsize,fso,filePath

allowsize=10*1024*1024'此处即为10 M
If Keyid<>1 And adminSize>0 Then allowsize=adminSize*1024

If not ifObjInstalled("Scripting.FileSystemObject") Then Call error2("你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能")

Set fso=Server.CreateObject("Scripting.FileSystemObject")
formPath = "upload/"&year(time_now)&"/"&Right("0"&month(time_now),2)&Right("0"&day(time_now),2)&"/"
filePath= Server.mappath("../../"& formPath)

call fCreateFolderByPath(fso, filePath)
Set fso=Nothing

filePath=filePath&"/"

randomize
ranNum=Right("0"&hour(time_now),2)&Right("0"&minute(time_now),2)&Right("0"&second(time_now),2)&int(90000*rnd)+10000

if adminUpload=1 then
	call UpFile2()
else
	call UpFile()
end if

'无惧上传
sub UpFile()
	set upload=new UpFile_Class '建立上传对象
	upload.GetData (allowsize) '取得上传数据

	if upload.err > 0 then
		select case upload.err
		case 1
			Call error2("请先选择你要上传的文件!")
		case 2
			Call error2("文件大小超过了限制"&forFileSize(adminSize)&"!请使用ftp上传！")
		end select
		exit sub
	else
	
		for each formName in upload.file '列出所有上传了的文件
			set file=upload.file(formName) '生成一个文件对象
			filesize=file.filesize
			if filesize=0 then
				Call error2("请先选择你要上传的文件！")
			end if

			fileEXT=file.fileEXT
			if CheckFileExtSafe(fileEXT)=true then
				Call error2("文件格式不正确！")
			end if

			filename=filePath&ranNum&"."&fileExt'生成文件绝对地址
			formPath=formPath&ranNum&"."&fileExt'生成文件相对地址
			
			if filesize>0 then '如果 FileSize > 0 说明有文件数据
				result=file.SaveToFile(filename) '保存文件
				if result="ok" then
					response.write "<br/>恭喜，上传成功！<br/>文件名：<input name="""&minute(time_now)&""&second(time_now)&""" value="""&formPath&"""/>"
				else
					response.write "<br/>Sorry，上传失败！"&result
				end if
			end if
			set file=nothing
		next
	end if
	set upload=nothing
end sub

'无名上传
sub UpFile2()
	set upload=new upload_5xsoft '建立上传对象
	for each formName in upload.objFile '列出所有上传了的文件
		set file=upload.file(formName) '生成一个文件对象
		filesize = file.filesize
		if filesize=0 then
			Call error2("请先选择你要上传的文件！")
		end if
		if filesize>allowsize Then
			Call error2("文件大小超过了限制"&forFileSize(adminSize)&"!请使用ftp上传！")
		end if

		fileExt=file.filename
		fileExt=Right(fileExt,Len(fileExt)-InStrRev(fileExt,"."))

		if CheckFileExtSafe(fileEXT)=true then
			Call error2("文件格式不正确！")
		end if

		filename=filePath&ranNum&"."&fileExt'生成文件绝对地址
		formPath=formPath&ranNum&"."&fileExt'生成文件相对地址
			
		if filesize>0 then '如果 FileSize > 0 说明有文件数据
			result = file.SaveAs(filename)'保存文件
			if result=FALSE then
				response.write "<br/>恭喜，上传成功！<br/>文件名：<input name="""&minute(time_now)&""&second(time_now)&""" value="""&formPath&"""/>"
			else
				response.write "<br/>Sorry，上传失败！"
			end if
		end if
		set file=nothing
	next
	set upload=nothing
end sub

w "<br/>-------------<br/><a href=""fileman.asp?sid="&sid&""">[文件管理]</a><br/><a href=""index.asp?sid="&sid&""">[站长工具]</a>"

Call Last2%>